﻿using System;
using System.Collections.Generic;
using System.Text;


namespace ttbit.IGL
{
    /// <summary>
    /// 将GL抽象出来，因为不同版本、平台的Opentk 兼容性不一，很讨厌
    /// </summary>
    public interface ITTGL
    {
        string GetVersion();


        void Enable(EnableCap cap);
        void Disable(EnableCap cap);

        void ActiveTexture(TextureUnit texturunit);
        //viewport

        void Viewport(int x, int y, int width, int height);
        void Scissor(int x, int y, int width, int height);
        void ClearColor(float r, float g, float b, float a);

        void Clear(ClearFlag flag = ClearFlag.ColorBufferBit);
        //shader 接口
        int CreateShader(ShaderType type);
        void DeleteShader(int shaderid);
        bool CompileShader(int shaderid, string code);
        string GetShaderInfoLog(int shaderid);

        int CreateProgram();
        void DeleteProgram(int progid);
        bool LinkProgram(int progid, int vsid, int fsid);
        string GetProgramInfoLog(int progid);

        int GetAttribLocation(int progid, string name);
        int GetUniformLocation(int progid, string name);

        void UseProgram(int progid);
        void Uniform1i(int uniid, int v);
        unsafe void Uniform1i(int uniid, int count, int* v);
        void Uniform1f(int uniid, float v);
        unsafe void Uniform1f(int uniid, int count, float* v);
        void Uniform2i(int uniid, int x, int y);
        unsafe void Uniform2i(int uniid, int count, int* v);
        void Uniform2f(int uniid, float x, float y);
        unsafe void Uniform2f(int uniid, int count, float* v);
        void Uniform3i(int uniid, int x, int y, int z);
        unsafe void Uniform3i(int uniid, int count, int* v);
        void Uniform3f(int uniid, float x, float y, float z);
        unsafe void Uniform3f(int uniid, int count, float* v);
        void Uniform4i(int uniid, int x, int y, int z, int w);
        unsafe void Uniform4i(int uniid, int count, int* v);
        void Uniform4f(int uniid, float x, float y, float z, float w);
        unsafe void Uniform4f(int uniid, int count, float* v);
        void UniformMatrix2(int uniid, int count, bool transpose, float[] v);
        unsafe void UniformMatrix2(int uniid, int count, bool transpose, float* v);

        void UniformMatrix2x3(int uniid, int count, bool transpose, float[] v);
        unsafe void UniformMatrix2x3(int uniid, int count, bool transpose, float* v);

        void UniformMatrix3(int uniid, int count, bool transpose, float[] v);
        unsafe void UniformMatrix3(int uniid, int count, bool transpose, float* v);
        void UniformMatrix4(int uniid, int count, bool transpose, float[] v);
        unsafe void UniformMatrix4(int uniid, int count, bool transpose, float* v);

        //texture
        int CreateTexture();
        void DeleteTexture(int texid);
        void BindTexture2D(int texid);

        void TexImage2D(int level, TextureType format, int width, int height);
        void TexImage2D<T>(int level, TextureType format, int width, int height, T[] data) where T : struct;
        void TexImage2D(int level, TextureType format, int width, int height, IntPtr data);
        unsafe void TexImage2D(int level, TextureType format, int width, int height, byte* data);

        void TexSubImage2D<T>(int level, TextureType format, int xoffset, int yoffset, int width, int height, T[] data) where T : struct;
        void TexSubImage2D(int level, TextureType format, int xoffset, int yoffset, int width, int height, IntPtr data);
        unsafe void TexSubImage2D<T>(int level, TextureType format, int xoffset, int yoffset, int width, int height, byte* data);

        void ReadPixels<T>(int x, int y, int width, int height, TextureType format, T[] buf) where T : struct;
        //sampler
        int CreateSampler();
        void DeleteSampler(int sampler);
        void SamplerParameter(int sampler, SamplerParameterName name, SamplerValue value);
        void BindSampler(int unit, int sampler);
        //fbo
        int CreateFrameBuffer();
        void DeleteFrameBuffer(int fboid);
        void FrameBufferTexture2D(FrameBufferSlot slot, int texid, int level);
        void BindFrameBuffer(int fboid);
        //blend
        void BlendEquation(BlendEquationMode mode);
        void BlendEquationSeparate(BlendEquationMode modeRGB, BlendEquationMode modeAlpha);
        void BlendFunc(BlendingFactorSrc sfactor, BlendingFactorDest dfactor);
        void BlendFuncSeparate(BlendingFactorSrc srcRGB, BlendingFactorDest dstRGB, BlendingFactorSrc srcAlpha, BlendingFactorDest dstAlpha);
        //vbo ebo vao
        int GenBuffer();
        int GenVertexArray();
        void DeleteBuffer(int bufid);
        void DeleteVertexArray(int vaoid);
        void BindVertexArray(int vaoid);
        void BindBuffer(BufferTarget traget, int bufid);
        void EnableVertexAttribArray(int index);
        void VertexAttribPointer(int index, int size, VertexAttribPointerType type, bool normalized, int stride, int offset);
        void BufferData<T>(BufferTarget traget, int count, T[] buffers, BufferUsage usage) where T : struct;
        void BufferData(BufferTarget traget, int count, IntPtr buffers, BufferUsage usage);
        unsafe void BufferData(BufferTarget traget, int count, byte* buffers, BufferUsage usage);
        //draw
        void DrawElements(BeginMode mode, int ebocount, DrawElementsType type, IntPtr indices);

        void DrawArrays(BeginMode mode, int first, int vcount);
    }
}
